import { useNavigate } from 'umi';

export const useAuth = () => {
  const navigate = useNavigate();

  let isLogin: boolean = localStorage.getItem('token') !== null;
  return {
    isLogin,
    login: (username: string, password: string) => {
      localStorage.setItem('token', username + '-' + password);
      navigate('/center');
    },
    logout: () => {
      localStorage.removeItem('token');
      navigate('/login');
    },
  };
};
